package edu.olin.scheduler.resources;

import edu.olin.scheduler.loader.ResourceLoader;
import java.net.URL;
import java.util.HashMap;
import javax.swing.Icon;
import javax.swing.ImageIcon;

public class IconLoader {
    
    private static final String ICON_PATH = "/edu/olin/scheduler/resources/icons/";
    
    public static final String ICON_COURSE = "course.png";
    public static final String ICON_COURSE_OPEN = "course_open.png";
    public static final String ICON_COURSE_SELECTED = "course_selected.png";
    
    private static HashMap<String,Icon> icons;
    
    public static Icon getIcon(String name){
        if(icons==null){ icons = new HashMap(); }
        if(icons.get(name)==null){ icons.put(name,loadIcon(name)); }
        return icons.get(name);
        }
    
    private static Icon loadIcon(String name){
        URL imageURL = ResourceLoader.getResourceURL(ICON_PATH+name);
        if(imageURL!=null){ return new ImageIcon(imageURL); } 
        return null;
        }
    
}
